package com.xzz;

import java.util.Arrays;

/**
 * @author 黄会准
 * @since 2020-11-17
 */
public class Shuffle {
    public static void main(String[] args) {
        int[] nums1 = {2, 5, 1, 3, 4, 7};
        int[] nums2 = {1,2,3,4,4,3,2,1};
        int[] nums3 = {1,1,2,2};
        System.out.println(Arrays.toString(shuffle(nums1, 3)));
        System.out.println(Arrays.toString(shuffle(nums2, 4)));
        System.out.println(Arrays.toString(shuffle(nums3, 2)));
    }

    public static int[] shuffle(int[] nums, int n) {
//        int[] result = new int[2 * n];
//        for (int i = 0,k=0, j = n; i < nums.length; i++) {
//            if (i % 2 == 0) {
//                result[i] = nums[k];
//                k++;
//            } else {
//                result[i] = nums[j];
//                j++;
//            }
//        }
//        return result;
        int [] ret = new int[2*n];
        for(int i=0;i<n;i++){
            ret[i*2]=nums[i];
            ret[i*2+1]= nums[n+i];
        }
        return ret;

    }
}
